package main.chapter4;/**
 * @Author xy
 * @Date 2020/6/11 21:22
 * @Description
 */

/**
 * 文件名称： main.chapter4.ParamTest.java</br>
 * 初始作者： xy</br>
 * 创建日期： 2020/6/11 21:22</br>
 * 功能说明： TODO <br/>
 * =================================================<br/>
 * 修改记录：<br/>
 * 修改作者        日期       修改内容<br/>
 * ================================================<br/>
 * Copyright (c) 2020-2021 .All rights reserved.<br/>
 */
public class ParamTest {
    public static void main(String[] args) {
        /**
         * Test1: Method can't modify numeric paramters
         */
        System.out.println("Testing tripValue:");
        double percent = 10;
        System.out.println("Before: percent="+ percent);
        tripleValue(percent);
        System.out.println("After: percent="+ percent);

        /**
         * Test2: Method can change the state of object paramters
         */
        System.out.println("\nTesting tripleSalary:");
        Employee3 harry = new Employee3("Harry",50000);
        System.out.println("Before: salary="+harry.getSalary());
        tripleSalary(harry);
        System.out.println("After: salary="+harry.getSalary());

        /**
         * Test3
         */
        System.out.println("\nTest swap");
        Employee3 a = new Employee3("Alice",70000);
        Employee3 b = new Employee3("Bob",60000);
        System.out.println("Before: a="+a.getName());
        System.out.println("Before: b="+b.getName());
        swap(a,b);
        System.out.println("After: a="+a.getName());
        System.out.println("After: b="+b.getName());

    }

    public static void tripleValue(double x){
        x= 3*x;
        System.out.println("End of method: x="+x);
    }

    public static void tripleSalary(Employee3 employee3){
        employee3.raiseSalary(200);
        System.out.println("End of method: salary="+employee3.getSalary());
    }

    public static void swap(Employee3 x,Employee3 y){
        Employee3 temp = x;
        x=y;
        y=temp;
        System.out.println("End of method: x="+x.getName());
        System.out.println("End of method: y="+y.getName());

    }

}
class Employee3{
    private String name;

    private double salary;

    public Employee3(String name, double salary) {
        this.name = name;
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public double getSalary() {
        return salary;
    }

    public void raiseSalary(double byPercent){
        double raise = salary*byPercent/100;
        salary+=raise;
    }
}
